package ualrcdg.client;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * This Class provides a way for the client
 * to log actions performed in the game
 * by the user.
 */
public class GameLogger
{
	String filename = "";
	private FileWriter filestream = new FileWriter(filename);
	private PrintWriter pw = new PrintWriter(filestream);
	private BufferedReader br = new BufferedReader(new FileReader(filename));
	
	/**
	 * This constructor creates a game logger 
	 * using the provided file name.
	 */
	public GameLogger(String filename) throws IOException 
	{
		this.filename = filename;
		filestream = new FileWriter(filename);
		br = new BufferedReader(new FileReader(filename));
		pw = new PrintWriter(filestream);
	}
	
	/**
	 * This method returns the first line
	 * in the file.
	 * @return a string of the first line read
	 * @throws IOException
	 */
	public String getFirstLine() throws IOException
	{
		return br.readLine();	
	}
	
	/**
	 * This method allows the game logger to 
	 * write to the file.
	 * @param event to be written to log file
	 */
	public void logEvent(String event)
	{
		pw.write(event + "\n");
	}
	
	/**
	 * This method closes the game
	 * logger file.
	 */
	public void closeFile()
	{
		pw.close();
	}
}
